﻿using System;
using System.Collections.Generic;
using System.Text;
using StockTrader.DAL.HastcAdapter.FileParser.Structure;
using StockTrader.DAL.IDAL;
using StockTrader.DAL.HastcAdapter.Config;

namespace StockTrader.DAL.HastcAdapter.FileMonitor.DataAccess
{
    public class DALclient
    {
        private IStsStocks dalStsStocks;

        public int CountSTS_STOCKSINFO()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_STOCKSINFO();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_STOCKSINFO()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_STOCKSINFO();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_STOCKSINFO(STS_STOCKSINFO item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_STOCKSINFO(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_STOCKSINFO(STS_STOCKSINFO item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_STOCKSINFO(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_MARKETINFO()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_MARKETINFO();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public int CountSTS_MARKETINFO_BYTIME(string time)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_MARKETINFO_BYTIME(time);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_MARKETINFO()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_MARKETINFO();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_MARKETINFO(STS_MARKETINFO item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_MARKETINFO(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_MARKETINFO(STS_MARKETINFO item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_MARKETINFO(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_TOP3_PRICE_A()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_TOP3_PRICE_A();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_TOP3_PRICE_A()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_TOP3_PRICE_A();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_TOP3_PRICE_A(STS_TOP3_PRICE_A item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_TOP3_PRICE_A(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_TOP3_PRICE_A(STS_TOP3_PRICE_A item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_TOP3_PRICE_A(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_TOP3_PRICE_B()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_TOP3_PRICE_B();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_TOP3_PRICE_B()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_TOP3_PRICE_B();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_TOP3_PRICE_B(STS_TOP3_PRICE_B item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_TOP3_PRICE_B(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_TOP3_PRICE_B(STS_TOP3_PRICE_B item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_TOP3_PRICE_B(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_ORDERS()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_ORDERS();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_ORDERS()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_ORDERS();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_ORDERS(STS_ORDERS item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_ORDERS(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_ORDERS(STS_ORDERS item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_ORDERS(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_TRADINGRESULT()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_TRADING_RESULT();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void DeleteSTS_TRADINGRESULT()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_TRADING_RESULT();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_TRADINGRESULT(STS_TRADING_RESULT item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_TRADING_RESULT(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSTS_TRADINGRESULT(STS_TRADING_RESULT item)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSTS_TRADING_RESULT(item);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_LE_ByCode(string code, decimal totalqtty)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_LE_ByCode(code, totalqtty);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public int CountSTS_LE()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                return dalStsStocks.CountSTS_LE();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public void DeleteSTS_LE()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.DeleteSTS_LE();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void InsertSTS_LE(DateTime time, string code, decimal stockid, decimal price, decimal quantity, decimal high, decimal low, decimal total)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.InsertSTS_LE(time, code, stockid, price, quantity, high, low, total);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }

        public void BackupHastc()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.BackupHastc();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void ClearHastc()
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.ClearHastc();
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
        public void UpdateSecuritiesInfo(int stockno, string symbol, string market)
        {
            dalStsStocks = StockTrader.DAL.Factory.StsStocksFactory.Create(Settings.DAL_TYPE);
            try
            {
                dalStsStocks.Open(Settings.CNN_STR);
                dalStsStocks.UpdateSecuritiesInfo(stockno, symbol, market);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalStsStocks.Close();
            }
        }
    }
}
